package com.liang.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.liang.pojo.User;
import com.liang.service.UserService;

@Controller
public class UserShiroController {
	/*
	 * @Autowired UserService userService;
	 * 
	 * @RequestMapping("/main") public String main(HttpServletRequest request,Model
	 * model) { return "main"; }
	 * 
	 * @RequestMapping("/toLogin") public String toLogin(HttpServletRequest
	 * request,Model model) { return "toLogin"; }
	 * 
	 * @RequestMapping("/login") public String login(User user,Model model) {
	 * Subject currentUser = SecurityUtils.getSubject(); Session session =
	 * currentUser.getSession(); session.setAttribute("info", user.getUsername());
	 * if(!currentUser.isAuthenticated()) { UsernamePasswordToken token = new
	 * UsernamePasswordToken(user.getUsername(),user.getPassword()); //
	 * token.setRememberMe(true); try { currentUser.login(token); return "main";
	 * }catch (UnknownAccountException uae) { model.addAttribute("msg", "用户名不存在");
	 * return "toLogin"; } catch (IncorrectCredentialsException ice) {
	 * model.addAttribute("msg2", "密码错误"); return "toLogin"; } catch
	 * (LockedAccountException lae) { model.addAttribute("msg", "拒绝访问"); return
	 * "toLogin"; } catch (AuthenticationException ae) { model.addAttribute("msg",
	 * "未知错误"); return "toLogin"; } } return "main"; }
	 * 
	 * @RequestMapping("/love") public String love() { return "love"; }
	 */
} 